word=input("输入单词,空格隔开")
t=input("请输入前几个出现次数最多的单词")
words=word.split(" ")
a=[]
b=[]
for i in words:
    if i in b:
        continues
    b.append(i)
    n=words.count(i)
    a.append([i,n])
# a.sort(key=lambda x:(-x[1],x[0]))
for i in range(len(a)-1):
    k=i
    for j in range(i+1,len(a)):
        if a[k][1]<a[j][1]:
            k=j
        elif a[k][1]==a[j][1]:
            if a[k][0]>a[j][0]:
                k=j
        else:
            pass
    if k!=i:
        a[k],a[i]=a[i],a[k]
print(a)
for i in range(int(t)):
    print(a[i][0],end=' ')
